package allrobots.DispensingMachineThread;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

class SendOrderSystem implements Runnable {
    private String orderNumber;
    private String serialNumber;

    public SendOrderSystem(String orderNumber,String serialNumber) {
        this.orderNumber = orderNumber;
        this.serialNumber=serialNumber;
    }

    @Override
    public void run() {
        try {
            // 使用 HttpClient 发起 HTTP GET 请求
            HttpClient client = HttpClient.newHttpClient();
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(new URI("http://192.188.123.2:4399/delivery_record/deliver_start?orderNumber=" + orderNumber + "&serialNumber=" + serialNumber))
                    .GET()
                    .build();

            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            // 打印响应
            if (response.statusCode() == 200) {
                System.out.println("发送成功");
            } else {
                System.out.println("请求失败，状态码：" + response.statusCode());
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("HTTP 请求发生异常");
        }
    }
}
